﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sinacor.Infra.Tools.ServiceRegistration.Entity
{
    public class Type : EntityBase
    {
        #region Attributes

        private int? _type_id;
        private int? _parent_type_id;        
        private string _namespace;
        private string _type_name;
        private string _description;
        private List<Attribute> _attributes;

        #endregion

        #region Constructor

        public Type()
        {

        }

        #endregion

        #region Properties

        public int? TypeId
        {
            get { return _type_id; }
            set { _type_id = value; }
        }

        public int? ParentTypeId
        {
            get { return _parent_type_id; }
            set { _parent_type_id = value; }
        }

        public string Namespace
        {
            get { return _namespace; }
            set { _namespace = value; }
        }

        public string TypeName
        {
            get { return _type_name; }
            set { _type_name = value; }
        }

        public string Description
        {
            get { return _description; }
            set { _description = value; }
        }

        public List<Attribute> Attributes
        {
            get { return _attributes; }
            set { _attributes = value; }
        }

        public string FullTypeName
        {
            get 
            {
                return String.IsNullOrEmpty(_namespace) ? _type_name : _namespace + "." + _type_name; 
            }
            set 
            {
                if (!string.IsNullOrEmpty(value))
                {
                    string[] values = value.Split('.');

                    if (values.Length > 1)
                    {
                        _namespace = value.Substring(0, value.LastIndexOf('.'));
                        _type_name = value.Substring(_namespace.Length + 1, (value.Length - _namespace.Length) - 1);
                    }
                    else
                    {
                        _namespace = string.Empty;
                        _type_name = value;
                    }
                }
            }
        }

        #endregion
    }
}
